<head>
 <style type="text/css"> 
        input.number { text-align:right; }
 </style>

</head>
<script type="text/javascript" charset="utf-8">
	$(function() {
		$('#dialog-form').load('<?php echo site_url(); ?>anggota/popup');
		$("#dialog-form").dialog({
			autoOpen: false,
			title: 'Anggota',
			height: 400,
			width: 712,
			modal: true,
			buttons: {
				'OK': function() {
					var chkIdx = $('input:radio:checked').val();
					var aData = popup_table.fnGetData(chkIdx);
					$("#anggotaID").val($("#id"+chkIdx).val());
					$("#anggota").val(aData[0]);
					$("#nama_anggota").val(aData[1]);
					$("#alamat_anggota").val(aData[2]);
					$("#pekerjaan_anggota").val(aData[3]);
					$(this).dialog('close');
				},
				'Batal': function() {
					$(this).dialog('close');
				}
			},
		});

		$('#anggota').focus(function() {
				$('#dialog-form').dialog('open');
			});

	});
</script>

<div class="post-title"><h2><a href="<?php echo current_url();?>"><?php echo $title; ?></a></h2></div>

<div class="post-body">

<div id="dialog-form"></div>

<?php
	echo form_open('simpananb/'.$form_act, 'id="simpananb_form"');

	echo "<div id='error' class='error-message' ";

	if($this->session->userdata('ERRMSG_ARR'))
	{
		echo ">";
		echo $this->session->userdata('ERRMSG_ARR');
		$this->session->unset_userdata('ERRMSG_ARR');
	}
	else
	{
		echo "style='display:none'>";
	}
	
	echo "</div>";

	$data['class'] = 'input';
	if ($act == 'view') $data['disabled'] = TRUE;
?>
	
	<table width="300" border="0" align="center" cellpadding="2" cellspacing="0">						  
		
		<tr>
			<th><?php echo form_label('Rek Simpanan Berjangka ','nama_simpananb'); ?></th>
			<td>
				<?php 
					$data['name'] = $data['id'] = 'nama_simpananb';
					if($act=='add')
					{ 
						if($new_id == ''){						
							$data['value'] = 'SB00001';
						}else{						
							$data['value'] = 'SB' . formatIdsimpananb(substr($new_id->nama_simpananb, 2) + 1);
						}
					}else{
						$data['value'] = (set_value('nama_simpananb')) ? set_value('nama_simpananb') : $simpananb_data['nama_simpananb'];
					}
					$data['title'] = "ID Simpanan Berjangka tidak boleh kosong";
					//echo form_input($data);
					echo "<input id='nama_simpananb' name='nama_simpananb' size='25' value='$data[value]' />
					 ";
				?>
				
				<?php 
				/*
					$data['name'] = $data['id'] = 'nama';
					$data['value'] = (set_value('nama')) ? set_value('nama') : $simpananb_data['nama_simpananb'];
					$data['title'] = "Nama simpananb tidak boleh kosong";
					//echo form_input($data);
					echo "<input id='nama' name='nama' size='25' class='required' value='$data[value]' />";
					*/
				?>
			</td>
			<th><?php echo form_label('Periode','periode'); ?></th>
			<td>
				<?php 				
					$data['name'] = $data['id'] = 'periode';
					$data['value'] = (set_value('periode')) ? set_value('periode') : $simpananb_data['periode'];
					$data['title'] = "Periode tidak boleh kosong";
					//echo form_input($data);
					echo "<input id='periode' name='periode' size='5' class='required number' value='$data[value]' />";					
				?>
			</td>
		</tr>
		<tr>
			<th colspan='2'><font color='red'>** Rek Simpanan Berjangka jangan diubah (otomatis dibuat) </font></th>
			<th>
				<?php echo form_label('Keterangan','keterangan'); ?>
			</th>
			<td>
				<?php 
					$data['name'] = $data['id'] = 'keterangan';
					$data['value'] = (set_value('keterangan')) ? set_value('keterangan') : $simpananb_data['keterangan'];
					unset($data['title']);
					echo "<input id='keterangan' name='keterangan' size='50' value='' />";	
				?>
			</td>
		</tr>
		<tr>
			<th><?php echo form_label('Tanggal Reg','tgl_reg'); ?></th>
			<td>
				<?php 
					$data['name'] = 'tgl_reg';
					//$data['id'] = 'datepicker2';
					if($act=='add')
					{ 
						$data['value'] = date("Y-m-d");;
					}else{					
						$data['value'] = (set_value('tgl_reg')) ? set_value('tgl_reg') : $simpananb_data['tgl_reg'];
					}
					$data['title'] = "Tanggal harus diisi dengan format dddd-mm-yy";				
					//echo form_input($data);
					echo "<input id='datepicker2' name='tgl_reg' size='15' class='required' value='$data[value]' />";
				?>
			</td>	
			
		</tr>
		
		<tr>
			<th colspan='2'><h4>Data Anggota</h4>
			</th>
			<th><h4>Data Simpanan Berjangka</h4></th>
			<td>
			</td>
		</tr>
		
		<tr>
			<th><?php echo form_label('ID Anggota *','anggota'); ?></th>
			<td>
				<?php 
					echo form_hidden('anggotaID',$simpananb_data['anggota_id']);

					$data['name'] = $data['id'] = 'anggota';
					$data['value'] = (set_value('anggota')) ? set_value('anggota') : $simpananb_data['nama_anggota'];
					$data['title'] = "Anggota tidak boleh kosong";
					//echo form_input($data);
					echo "<input id='anggota' name='anggota' size='25' class='required' value='$data[value]' />";
				?>
			</td>	
			<th><?php echo form_label('Masa Simpanan','masa_simpanan'); ?></th>
			<td>
				<?php 
					$data['name'] = $data['id'] = 'masa_simpanan';
					$data['value'] = (set_value('masa_simpanan')) ? set_value('masa_simpanan') : $simpananb_data['masa_simpanan'];
					unset($data['title']);	
					//echo form_input($data);
					echo "<input id='masa_simpanan' name='masa_simpanan' size='5' class='required number' value='$data[value]' />";
				?>
			</td>
		</tr>
		<tr>
			<th><?php echo form_label('Nama','nama_anggota'); ?></th>
			<td>
				<?php 
					echo "<input id='nama_anggota' name='nama_anggota' size='25' class='required' value='$data[value]' disabled='1'/>";
				?>
			</td>	
			<th><?php echo form_label('Bunga','bunga'); ?></th>
			<td>
				<?php 
					$data['name'] = $data['id'] = 'bunga_persen';
					$data['value'] = (set_value('bunga_persen')) ? set_value('bunga_persen') : $simpananb_data['bunga_persen'];
					//unset($data['title']);
					echo "<input id='bunga_persen' name='bunga_persen' size='2' class='required number' value='$data[value]' maxlength='3' /> %"; 
					
				?>
			</td>
		</tr>
		<tr>
			<th><?php echo form_label('Alamat','alamat_anggota'); ?></th>
			<td>
				<?php 
					/*
					echo form_hidden('anggotaID',$simpananb_data['anggota_id']);
				
					$data['name'] = $data['id'] = 'anggota';
					$data['value'] = (set_value('anggota')) ? set_value('anggota') : $simpananb_data['nama_anggota'];
					$data['title'] = "Anggota tidak boleh kosong";
					*/
					
					//echo "<textarea id='alamat_anggota' name='alamat_anggota' rows='3' cols='25' class='required' value='$data[value]' disabled='1'/></textarea>";
					echo "<input id='alamat_anggota' name='alamat_anggota' size='25' class='required' value='$data[value]' disabled='1'/></textarea>";
				?>
			</td>	
			<th><?php echo form_label('Tanggal Jatuh Tempo','tgl_jatuh_tempo'); ?></th>
			<td>
				<?php 
					$data['name'] = 'tgl_jatuh_tempo';
					//$data['id'] = 'datepicker3';
					if($act=='add')
					{ 
						$data['value'] = date("Y-m-d");;
					}else{					
						$data['value'] = (set_value('tgl_jatuh_tempo')) ? set_value('tgl_jatuh_tempo') : $simpananb_data['tgl_jatuh_tempo'];
					}
					$data['title'] = "Tanggal harus diisi dengan format dddd-mm-yy";				
					//echo form_input($data);
					echo "<input id='datepicker3' name='tgl_jatuh_tempo' size='15' class='required' value='$data[value]' />";
				?>
			</td>	
		</tr>
		<tr>
			<th><?php echo form_label('Pekerjaan','pekerjaan_anggota'); ?></th>
			<td>
				<?php 
					
					echo "<input id='pekerjaan_anggota' name='pekerjaan_anggota' size='25' class='required' value='' disabled='1'/>";
				?>
			</td>
			<th><?php echo form_label('Administrasi','administrasi'); ?></th>
			<td>
				<?php
					$data['name'] = $data['id'] = 'administrasi';
					$data['value'] = (set_value('administrasi')) ? set_value('administrasi') : $simpananb_data['administrasi'];
					echo "<input id='administrasi' name='administrasi' size='30' class='required number' value='$data[value]'/>";	
				?>
			</td>
		</tr>		
		<tr>
			<th>				
			</th>
			<td>					
			</td>
			<th><?php echo form_label('Setoran','setoran'); ?></th>
			<td>
				<?php 
					$data['name'] = $data['id'] = 'setoran';
					$data['value'] = (set_value('setoran')) ? set_value('setoran') : $simpananb_data['setoran'];
					//unset($data['title']);
					echo "<input id='setoran' name='setoran' size='30' class='required number' value='$data[value]'/>";	
				?>
			</td>
			
			
		</tr>
		<tr>
			<th>
			</th>
			<td>
			</td>
			<th><?php echo form_label('Total','total'); ?></th>
			<td>
				<?php 
					$data['name'] = $data['id'] = 'total';
					$data['value'] = (set_value('total')) ? set_value('total') : $simpananb_data['total'];
					//unset($data['title']);
					echo "<input id='total' name='total' size='30' class='required number' value='$data[value]'/>";	
				?>
			</td>
						
		</tr>
		<tr>
			<th>
			</th>
			<td>
			</td>			
		</tr>
		
		<tr>
			<th><?php echo form_label('Bunga per Bulan','bunga_per_bulan'); ?></th>
			<td>
				<?php 
					$data['name'] = $data['id'] = 'bunga_per_bulan';
					$data['value'] = (set_value('bunga_per_bulan')) ? set_value('bunga_per_bulan') : $simpananb_data['bunga_per_bulan'];
					//unset($data['title']);
					echo "<input id='bunga_per_bulan' name='bunga_per_bulan' size='30' class='required number' value='$data[value]'/>";	
				?>
			</td>
			<th><?php echo form_label('Total Bunga','total_bunga'); ?></th>
			<td>
				<?php 
					$data['name'] = $data['id'] = 'total_bunga';
					$data['value'] = (set_value('total_bunga')) ? set_value('total_bunga') : $simpananb_data['total_bunga'];
					//unset($data['title']);
					echo "<input id='total_bunga' name='total_bunga' size='30' class='required number' value='$data[value]'/>";	
				?>
			</td>			
		</tr>
		
		<tr>
			<th>
			</th>
			<td>
			</td>
			<th></th>
			<td>
			</td>			
		</tr>
		
		
			
	</table>
	
	<div class="buttons">
		<?php 
			if($act!='view')
			{ 
				echo form_submit('simpan','Simpan', "id = 'button-save'" );
				echo form_reset('reset','Reset', "id = 'button-reset'" );
				echo form_button(array('id' => 'button-cancel', 'content' => 'Batal', 'onClick' => "location.href='".site_url()."simpananb'" ));
			}
			else
			{
				echo form_button(array('id' => 'button-cancel', 'content' => 'Kembali', 'onClick' => "location.href='".site_url()."simpananb'" ));
			}
		?>				
	</div>
	
<?php echo form_close(); ?>

</div>

<script type='text/javascript'>
	//Validasi di client
		
	$(document).ready(function(){
		$("#simpananb_form").validate({
			messages: {
					biaya: " Biaya harus diisi"
			}
		});
    });
  
	/*
	$(document).ready(function()
	{
		$('#simpananb_form').validate({
			errorLabelContainer: "#error",
			wrapper: "li",
			rules: 
			{
				nama: "required",
				anggota: "required",
				tgl_reg: "dateISO",
				biaya: "integer""
			}
		});
	});
	*/
</script>
<?php
	function formatIdsimpananb($id){		
		if (strlen($id) == 1)
		{
			return '0000' . $id;
		}
		else if (strlen($id) == 2)
		{
			return '000' . $id;
		}
		else if (strlen($id) == 3)
		{
			return '00' . $id;
		}
		else if (strlen($id) == 4)
		{
			return '0' . $id;
		}
		else {
			return $id;
		}
	}
?>